package cn.sanshuilin.kst.system.provider.write.dao;

import cn.sanshuilin.kst.system.provider.bean.Ad;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author greenlee
 * @version v1.0
 * @create 创建时间: 2017-11-28 15:49
 * Copyright 2017  by 三水林科技有限公司
 **/
public interface AdDao extends JpaRepository<Ad,String> {
    Ad findById(String id);
// String hql = "FROM Ad m  WHERE Code=:Code ORDER BY m.ID";
    @Transactional
    @Query(value = "SELECT * FROM Ad m  WHERE Code=:Code ORDER BY m.ID",nativeQuery = true)
    List<Ad> findByCodeOrderById(@Param("Code") String Code);

    @Transactional
    @Query(value="SELECT a SELECT Ad WHERE ID = ( SELECT ID SELECT Ad WHERE ID > :ID order by id asc limit 1)",nativeQuery = true)
    List<Ad> getNextAds(@Param("ID") String ID);
}
